<template>
  <!-- 领导指示 -->
  <h-modal class="event-modal" v-model.lazy="show" title="领导指示" @submit="submit">
    <a-form-model ref="ruleForm" :model="form" :rules="rules" size="large">
      <a-row :gutter="100">
        <a-col :span="12">
          <a-form-model-item label="时间">
            {{ moment().format('YYYY-MM-DD HH:mm:ss') }}
          </a-form-model-item>
        </a-col>
        <!-- <a-col :span="12">
          <a-form-model-item label="办理状态" prop="transactStatus">
            <a-select v-model.lazy="form.transactStatus" placeholder="请选择办理状态">
              <a-select-option :value="0">协办</a-select-option>
              <a-select-option :value="1">查办</a-select-option>
              <a-select-option :value="2">督办</a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col> -->
        <!-- <a-col :span="12">
          <a-form-model-item label="事件等级" prop="eventGrade">
            <a-radio-group buttonStyle="solid" v-model.lazy="form.eventGrade">
              <a-radio-button :value="0">普通预警</a-radio-button>
              <a-radio-button class="radio-button-yellow" :value="1">中级预警 </a-radio-button>
              <a-radio-button class="radio-button-orange" :value="2">高级预警</a-radio-button>
              <a-radio-button class="radio-button-red" :value="3">特级预警</a-radio-button>
            </a-radio-group>
          </a-form-model-item>
        </a-col> -->
        <a-col :span="12">
          <a-form-model-item label="领导指示">
            <!-- <a-input v-model.lazy="form.leader" :maxLength="50" placeholder="请输入领导指示"></a-input> -->
            <a-select style="width: 100%" placeholder="请输入领导指示" v-model="form.leader">
              <a-select-option v-for="item in leader" :value="item.realname" :key="item.mobile">
                {{ item.realname }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :span="24">
          <a-form-model-item label="指示内容" prop="content">
            <a-textarea :rows="6" v-model.lazy="form.content" :maxLength="300" placeholder="请输入指示内容"></a-textarea>
          </a-form-model-item>
        </a-col>
      </a-row>

    </a-form-model>
  </h-modal>
</template>

<script>
import moment from 'moment';
import { addLeader, getDivisionHead } from '@/api/serve';
import cloneDeep from 'lodash/cloneDeep';

export default {
  props: {
    showModal: {
      type: Boolean,
      default: false
    },
    formData: {
      type: Object,
      default: () => {}
    },
    eventId: {
      type: String,
      default: ''
    },
    dateDuty: {
      type: String,
      default: ''
    }
  },
  model: {
    prop: 'showModal',
    event: 'update:showModal'
  },
  watch: {
    showModal: {
      handler(val) {
        this.show = val;
        if (val) this.getLeader();
      },
      immediate: true
    },
    show(val) {
      this.$emit('update:showModal', val);
    }
  },
  data() {
    return {
      moment,
      show: false,
      deptArr: [],
      dept: [],
      form: {
        // transactStatus: 0,
        eventGrade: 0
      },
      rules: {
        leader: [{ required: true, message: '请输入' }],
        transactStatus: [{ required: true, message: '请输入' }],
        eventGrade: [{ required: true, message: '请输入' }],
        content: [{ required: true, message: '请输入' }]
      },
      leader: []
    };
  },
  created() {

  },
  methods: {
    edit(formData) {
      this.form = cloneDeep(formData);
    },
    getLeader() {
      getDivisionHead().then(res => {
        this.leader = res.data;
        res.data.forEach(e => {
              if (e.realname === this.dateDuty) {
                this.form.leader = e.realname;
              }
            });
        console.log('[this.leader]', this.leader);
      });
    },
    handleChange() {

    },
    submit() {
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          this.form.eventId = this.eventId;
          addLeader(this.form).then(res => {
            this.$message.success('创建成功');
            this.show = false;
            this.$emit('submit', true);
            this.form = {
              // transactStatus: 0,
              eventGrade: 0
            };
          });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    }
  }
};
</script>

<style>

</style>
